import tool from '../tool'
import util from '_util/index'
import model from '_model'
import _ from 'lodash'
import in_array from 'in_array'

export default{
    detailCom(_this, ctl, id){
        let _model = model[ctl];
        if (_model && _model.showPopDetail)
            _model.showPopDetail(_this, id);
    },
    show_click_see(_this, info){
        let eventVue = util.store.get(_this,'eventVue');
        eventVue.$emit('up_click_see_conf', info);
        eventVue.$emit('showDetailModal');
    },
    showFields(ctl){
        return util.modelFn(ctl, 'detailShowFields');
    },
    get_chunked(_this, ctl){
        let tmp = [];
        let _model = model[ctl];
        if (_model && _model.get_chunked)
            tmp = _model.get_chunked(_this);
        return tmp.length > 0 ? tmp : null;
    },
    getDetail(_this, id, field = null){
        // let eventVue = util.store.get(_this,'eventVue');
        // eventVue.$emit('getDetailById', id);
        // let rs = util.store.getResult(_this, 'getDetailById');


        let items = util.store.get(_this, 'list_data', 'list');
        let rs = items.filter(item => {
            return item[0].val == id;
        })[0];
        if (field) {
            rs = rs.find(item => {
                return item.field == field;
            });
        }
        return rs;
    },
    get_not_list_field_info(_this, id){
        let eventVue = util.store.get(_this,'eventVue');
        eventVue.$emit('get_not_list_field_info', id);
        let rs = util.store.getResult(_this, 'get_not_list_field_info');
        return rs;
    },
    get_detail_info(_this, id){
        if (id) {
            let _model = model[_this.ctl];
            if (_model && _model.get_detail_info)
                _model.get_detail_info(_this, id);
        }
    },
    get_use_detail(_this){
        let tmp = '';
        switch (_this.ctl) {
//        case 'Trodetail':
//
//          break;
            default:
                tmp = _this.ctl;
        }
        if (in_array(tmp, ['Trodetail']))
            return tmp;
        else
            return null;
        return tmp
    },

    /**
     * 供应商订单相关
     * */
    spDelivery(_this, id){
        model['Trosp'].spDelivery(_this, id);
    },
    spAuditfc(_this, id){
        model['Trosp'].spAuditfc(_this, id);
    }
}
